#!/usr/bin/perl -w
use strict;

my $cnt_mims = 0;
my %mims;
while (<>)
{
	/	^							# start at beginning of line
		([^|]*)\|					# save disease field (not including | terminator)
		(?:[^|]*\|)					# ignore next field
		([^|]*)						# save mim code field
						/x;
	if ($1 ne '' && $2 ne '')
	{
		my ($mim, $dis) = ($2,$1);
		
		if ($dis !~ /^(		[?\[]		|		# not begin with ? or [
							(\{\?)		)	/x)	# or {?
		{
			$mims{$mim} = 0 if (!defined $mims{$mim});
			++$mims{$mim};
		
#			print "$mim,$dis\n";
			++$cnt_mims;
		}
	}
}
print join "\n", sort {$a <=> $b} keys %mims;
print STDERR "\t", scalar keys %mims, "\tMIM codes were retrieved.\n";
print STDERR "\t\t($cnt_mims disease entries were associated with MIM codes.)\n";
my $cntduplicates = 0;
foreach (keys %mims)
{
	++$cntduplicates if ($mims{$_} > 1);
}
exit unless $cntduplicates;

if ($cntduplicates > 1)
{
	print STDERR "\t\t($cntduplicates MIM codes".
					" were associated with > 1 disease entry.)\n";
}
else
{
	print STDERR "\t\t(1 MIM code was associated with > 1 disease entry.)\n";	
}	
